﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Pages
{
    public partial class MessageColorBox : PageBaseFrontend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (base.IsVerified)
                {
                    if (Request["requestID"] != null)
                    {
                        string userid = Request["userID"];
                        string requestid = Request["requestID"];

                        Model.RequestInfo req = BLL.RequestInfoBLL.Instance.GetDetail(requestid);
                        if (req != null)
                        {
                            imgUserPhoto.Src = req.User.PhotoPath;
                            lbUserName.Text = req.User.UserName;
                            lbRequestTitle.Text = req.Title;
                        }
                        else
                        {
                            Response.Write("参数错误！");
                        }
                    }
                    if (Request["userID"] != null)
                    {
                        if (base.VerifiedUserID == Request["userID"])
                        {
                            lbMessage.Text = "您不能发送消息给自己！";
                            ibtnSend.Enabled = false;
                        }
                    }
                }
                else
                {
                    Response.Redirect("/Pages/LoginColorBox.aspx");
                }
            }
        }

        //发送消息
        protected void ibtnSend_Click(object sender, ImageClickEventArgs e)
        {
                if (Request["userID"] != null)
                {
                    Model.Message message = new Model.Message();
                    message.MessageID = Guid.NewGuid().ToString();
                    if (txtContent.Text.Trim() != "")
                    {
                        message.Content = this.txtContent.Text.Trim();
                    }
                    else
                    {
                        lbMessage.Text = "信息不能为空！";
                        return;
                    }
                    message.RefServiceID = Request["serviceID"] ?? "";
                    message.RefRequestID = Request["requestID"] ?? "";
                    message.Sender = base.VerifiedInfo.User.UserID;
                    message.Receiver = Request["userID"].ToString();
                    message.ResourcePath = "";// hfpath.Value;
                    message.IsRead = false;

                    BLL.MessageBLL.Instance.SendMessage(message);

                    this.txtContent.Text = "";
                    lbMessage.Text = "发送成功！";
                    base.CloseThickBox(false);
                }
                else
                {
                    
                }
        }
    }
}